<?php
/**
 * This class allow you to access to Environment variables.
 * @package    opensocial
 * @subpackage environment
 * @author     Daniel Botelho <botelho.daniel@gmail.com>
 */
class OSEnvironment implements Instanciatable
{
  const ENVIRONMENT_CLASS = 'opensocial.Environment';
  
  private $env_var;
  private $initizalized;
  
  /**
   * This is the constructor. To initalize this variable you need to call the method "initialize()"
   * @param string The name of this OSEnvironment variable
   */
  public function __construct($env_var=null){
    $this->env_var = $env_var;
    $this->initizalized = false;
  }
  
  public function initialized()
  {
  	return $this->initizalized;
  }
  
  /**
   * This method will init the environment variable so you can use this class
   * @return string HTML string that initializes this variable
   * @param boolean $initialize By default it initializes the variable
   */
  public function initialize($initialize=true,$appendable=false)
  {
  	$this->initizalized = true;
  	$html = '';
  	if($this->env_var){
  	  if($initialize)
  	    $html = 'var '. $this->env_var." = opensocial.getEnvironment();\n";
  	  else
  	    $html = "opensocial.getEnvironment();\n";
  	}
  	return $html;
  }
  
  /**
   * This method returns the variable name of this Environment class
   * @return string The variable used for this Environment
   */
  public function getVarName(){ return $this->env_var; }

  /**
   * Returns the current domain — for example, "orkut.com" or "myspace.com". 
   * @param boolean If the command is appendable
   * @return string Returns the current domain — for example, "orkut.com" or "myspace.com".
   */
  public function getDomainName($appendable=false)
  {
  	$html = ''; 
  	if($this->getVarName())
  	  $html.= $this->getVarName();
  	else
  	  $html.= 'opensocial.getEnvironment()';
  	return StringUtil::appendableString($html.'.getDomain()',$appendable); 
  }

  /**
   * Returns true if this container supports some OSActivityField
   * @param string $fieldName Look at OSActivityField to see the allowed field types
   * @param boolean If the command is appendable
   * @return string If some Activity supports some $fieldName
   */
  public function supportsActivity(/*OSField*/ $fieldName,$appendable=false)
  { 
    return StringUtil::appendableString($this->getVarName().'.supportsField('.OSEnvironmentObjectType.ACTIVITY.','.$fieldName.')',$appendable);
  }

  /**
   * Returns true if this container supports some OSActivityMediaItem
   * @param string $fieldName Look at OSActivityField to see the allowed field types
   * @param boolean If the command is appendable
   * @return string If some Activity supports some $fieldName
   */
  public function supportsActivityMediaItem(/*OSField*/ $fieldName,$appendable=false)
  { 
    return StringUtil::appendableString($this->getVarName().'.supportsField('.OSEnvironmentObjectType.ACTIVITY_MEDIA_ITEM.','.$fieldName.')',$appendable);
  }

  public function supportsAddress(/*OSField*/ $fieldName,$appendable=false)
  { 
    return StringUtil::appendableString($this->getVarName().'.supportsField('.OSEnvironmentObjectType.ADDRESS.','.$fieldName.')',$appendable);
  }

  public function supportsBodyType(/*OSField*/ $fieldName,$appendable=false)
  { 
    return StringUtil::appendableString($this->getVarName().'.supportsField('.OSEnvironmentObjectType.BODY_TYPE.','.$fieldName.')',$appendable);
  }

  public function supportsEmail(/*OSField*/ $fieldName,$appendable=false)
  { 
    return StringUtil::appendableString($this->getVarName().'.supportsField('.OSEnvironmentObjectType.EMAIL.','.$fieldName.')',$appendable);
  }

  public function supportsFilterType(/*OSField*/ $fieldName,$appendable=false)
  { 
    return StringUtil::appendableString($this->getVarName().'.supportsField('.OSEnvironmentObjectType.FILTER_TYPE.','.$fieldName.')',$appendable);
  }

  public function supportsMessage(/*OSField*/ $fieldName,$appendable=false)
  { 
    return StringUtil::appendableString($this->getVarName().'.supportsField('.OSEnvironmentObjectType.MESSAGE.','.$fieldName.')',$appendable);
  }

  public function supportsMessageType(/*OSField*/ $fieldName,$appendable=false)
  { 
    return StringUtil::appendableString($this->getVarName().'.supportsField('.OSEnvironmentObjectType.MESSAGE_TYPE.','.$fieldName.')',$appendable);
  }

  public function supportsName(/*OSField*/ $fieldName,$appendable=false)
  { 
    return StringUtil::appendableString($this->getVarName().'.supportsField('.OSEnvironmentObjectType.NAME.','.$fieldName.')',$appendable);
  }

  public function supportsOrganization(/*OSField*/ $fieldName,$appendable=false)
  { 
    return StringUtil::appendableString($this->getVarName().'.supportsField('.OSEnvironmentObjectType.ORGANIZATION.','.$fieldName.')',$appendable);
  }

  public function supportsPerson(/*OSField*/ $fieldName,$appendable=false)
  { 
    return StringUtil::appendableString($this->getVarName().'.supportsField('.OSEnvironmentObjectType.PERSON.','.$fieldName.')',$appendable);
  }

  public function supportsPhone(/*OSField*/ $fieldName,$appendable=false)
  { 
    return StringUtil::appendableString($this->getVarName().'.supportsField('.OSEnvironmentObjectType.PHONE.','.$fieldName.')',$appendable);
  }

  public function supportsSortOrder(/*OSField*/ $fieldName,$appendable=false)
  { 
    return StringUtil::appendableString($this->getVarName().'.supportsField('.OSEnvironmentObjectType.SORT_ORDER.','.$fieldName.')',$appendable);
  }

  public function supportsURL(/*OSField*/ $fieldName,$appendable=false)
  { 
    return StringUtil::appendableString($this->getVarName().'.supportsField('.OSEnvironmentObjectType.URL.','.$fieldName.')',$appendable);
  }


}
